package com.wj.constant;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 *  商品分类枚举
 */
@Getter
@AllArgsConstructor
public enum GoodsCategory {

    BRAND_A("1001","电器"),
    BRAND_B("1002","家具"),
    BRAND_C("1003","服饰"),
    BRAND_D("1004","母婴"),
    BRAND_E("1005","食品");

    // 商品分类编码
    private final String code;

    // 商品分类描述信息
    private final String description;


    public static GoodsCategory of(String code){
        Objects.requireNonNull(code);

        return Stream.of(values())
                .filter(bean -> bean.code.equals(code))
                .findAny()
                .orElseThrow(
                        () -> new IllegalArgumentException(code + "not exists")
                );
    }
}
